package main

import (
	"fmt"
	"strconv"
	"time"
)

//循环中采用协程并行处理
//利用管道等待结果
func main() {
	var size int = 100000
	sem := make(chan byte, size)
	for i := 0; i < size; i++ {
		go func(innerI int) {
			doSomething(innerI)
			sem <- 1
		}(i)
	}
	for i := 0; i < size; i++ {
		<-sem
	}
	fmt.Println("全部计算结束")
}

func doSomething(num int) {

	time.Sleep(1 * time.Second)
	fmt.Println("计算完成：" + strconv.Itoa(num))
}
